<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>财务结算明细</title>

<link rel="stylesheet" href="<?php echo $this->getWebSkinPath()."bootstr/css/bootstrap.min.css";?>">
<link rel="stylesheet" href="<?php echo $this->getWebSkinPath()."bootstr/css/bootstrap-theme.min.css";?>">
<script type="text/javascript" src="<?php echo $this->getWebSkinPath()."bootstr/js/jquery-1.9.1.js";?>"></script>
<script type="text/javascript" src="<?php echo $this->getWebSkinPath()."bootstr/js/bootstrap.min.js";?>"></script>

<style type="text/css">
.bill_content{
	/*border: 1px solid red;*/
}

.d_table{
	width: 90%;
	margin: 0 auto;
}

.red{
	color: red;
}

</style>

</head>
<body>
<div class="page-header container">
  <h1>财务结算详情<small>----------商家申请结算</small></h1>
</div>

<?php 
	//echo "<pre>";
	//print_r($this->result);
	//echo "</pre>";
?>

<div class="bill_content">
	<div class="d_table">
		<table class="table table-bordered table-hover">
			<thead >
				<tr class="info">
					<td>订单类型</td>
					<td>同意结算时间</td>
					<td>订单号</td>
					<td>买家id</td>
					<td>买家名称</td>
					<td>商家id</td>
					<td>商家名称</td>
					<td>订单金额</td>
					<td>费用</td>
					<td>退款</td>
					<td>结算金额</td>
					<td>状态</td>
					
				</tr>
			</thead>
			
			<tbody>
			<?php foreach($this->result as $key => $data){?>
			
				<?php 
					//$res = json_decode($data['log'],true);
				//	$log_data = $res['data'];
					//echo "<pre>";
					//print_r($data);
					//echo "</pre>";
					
				?>
				
				<tr>
					<td><?php echo isset($data[0]['order_type'])?$data[0]['order_type']:"";?></td>
					<td><?php echo isset($data['apply_time'])?$data['apply_time']:"";?></td>
					<td><?php echo isset($data[0]['no'])?$data[0]['no']:"";?></td>
					<?php $orderno = $data[0]['no']?>
					<?php $query = new IQuery("order");$query->where = "order_no = $orderno";$order = $query->find(); foreach($order as $key => $item){?>
						<?php $good_order = "order"?>
					<?php }?>
					
					<?php if(!$good_order){?>
						<?php $good_order = "vr_order"?>
					<?php }?>
					
					
					<?php $query = new IQuery("$good_order");$query->where = "order_no = $orderno";$items = $query->find(); foreach($items as $key => $o){?>
						<?php 
							//echo "<pre>";
							//print_r($o);
							//echo "</pre>";
						?>
						<td><?php echo isset($o['buyer_id'])?$o['buyer_id']:"";?></td>
						
						<?php if($o['order_type'] == 'vr'){?>
						<?php $uid = $o['buyer_id']?>
						<?php $query = new IQuery("user");$query->where = "id = $uid";$items = $query->find(); foreach($items as $key => $u){?>
							<td><?php echo isset($u['username'])?$u['username']:"";?></td>
						<?php }?>
						
						<?php }else{?>
						<td><?php echo isset($o['accept_name'])?$o['accept_name']:"";?></td>
						<?php }?>
						<td><?php echo isset($o['seller_id'])?$o['seller_id']:"";?></td>
						<td><?php echo isset($o['store_name'])?$o['store_name']:"";?></td>
						<?php $isfinal = $o['final_settl']?>
					<?php }?>
					
					
					<td class="red">¥<?php echo isset($data[0]['sum'])?$data[0]['sum']:"";?></td>
					<td class="red">¥<?php echo isset($data[0]['tichen'])?$data[0]['tichen']:"";?></td>
					<td class="red">¥<?php echo isset($data[0]['refund'])?$data[0]['refund']:"";?></td>
					<td class="red">¥<?php echo isset($data[0]['real_Sum'])?$data[0]['real_Sum']:"";?></td>
					<td>
						<?php if($isfinal == 0){?>
						<a val="<?php echo isset($data[0]['no'])?$data[0]['no']:"";?>" type="<?php echo isset($o['order_type'])?$o['order_type']:"";?>" class="btn btn-default unsettled"  href="javascript:" role="button">未结算</a>
						<?php }else{?>
							<a val="<?php echo isset($data[0]['no'])?$data[0]['no']:"";?>" class="btn btn-default disabled" href="#" role="button" >已结算</a>
						<?php }?>
					</td>
				</tr>
			<?php }?>
			</tbody>
		
		</table>
		
	</div>
</div>
</body>

<script type="text/javascript">
	$(".unsettled").each(function(){
		$(this).click(function(){
			
			var order_id = $(this).attr("val");
			var type = $(this).attr("type");
			
			console.log(order_id+" "+type);
			
			var xhr = new XMLHttpRequest();
			var url = "<?php echo IUrl::creatUrl("market/detailsUpdate");?>";
			xhr.open('POST',url,true);
			var formData = new FormData();
			formData.append("order_id",order_id);
			formData.append("type",type);
			
			xhr.onload = function(){
				var msg = this.responseText;
				//console.log(msg);
				window.location.reload();
			}
			
			xhr.send(formData);
			
		});
	});
</script>

</html>